package com.blog.attach.service.impl;

import com.blog.attach.entity.UserReplay;
import com.blog.attach.entity.VO.UserReplayVO;
import com.blog.attach.mapper.UserCommentMapper;
import com.blog.attach.mapper.UserReplayMapper;
import com.blog.attach.service.UserReplayService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 苏离
 * @since 2022-01-18
 */
@SuppressWarnings("all")
@Slf4j
@Service
@Transactional
public class UserReplayServiceImpl extends ServiceImpl<UserReplayMapper, UserReplay> implements UserReplayService {

@Autowired
    UserReplayMapper replayMapper;
@Autowired
    UserCommentMapper commentMapper;
    @Override
    public Map<String, Object> getReplays(Integer parentId, Integer pageNo, Integer limit) {
        pageNo=(pageNo-1)*limit;
        List<UserReplayVO> replaysByParentId = replayMapper.getReplaysByParentId(parentId, pageNo, limit);
        Map map=new HashMap();
        map.put("replays", replaysByParentId);
        return map;
    }

    @Override
    public boolean insertReplay(String userId, String BeUserId, Integer parentId,String replayContent) {
        UserReplay replay=new UserReplay();
        replay.setUserId(userId).setReplayUserId(BeUserId).setParentId(parentId).setReplayContent(replayContent);
        commentMapper.updateReplayCount(parentId);
        int insert = replayMapper.insert(replay);
        if(insert>0)
            return true;
        return false;
    }
}
